unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Btnx_1: TButton;
    lst1: TListBox;
    Btnx_2: TButton;
    Btnx_3: TButton;
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  TypInfo,Unit2;
  
{$R *.dfm}

procedure GetClassProperties(AClass: TClass; AStrings: TStrings);
var
 PropCount, I: SmallInt;
 PropList: PPropList;
 PropStr: string;
begin
  PropCount := GetTypeData(AClass.ClassInfo).PropCount;
  GetPropList(AClass.ClassInfo, PropList);
  for I := 0 to PropCount - 1 do
  begin
    case PropList[I]^.PropType^.Kind of
      tkClass   : PropStr := '[Class] ';
      tkMethod   : PropStr := '[Method]';
      tkSet    : PropStr := '[Set]  ';
      tkEnumeration: PropStr := '[Enum] ';
    else
      PropStr := '[Field] ';
    end;
      PropStr := PropStr + PropList[I]^.Name;
      PropStr := PropStr + ': ' + PropList[I]^.PropType^.Name;
      AStrings.Add(PropStr);
  end;
  FreeMem(PropList);
end;

procedure TForm1.Btnx_1Click(Sender: TObject);
begin
  GetClassProperties(TButton, lst1.Items);  
end;

procedure TForm1.Btnx_2Click(Sender: TObject);
var
  I:Integer;
  CtrlA:TControl;
begin
  lst1.Items.Clear;
  
  for I:=0 to self.ControlCount-1 do
  begin
    CtrlA:=TControl(Controls[I]);
    if CtrlA is TButton then
    begin
      lst1.Items.Add(TButton(CtrlA).Name);
      lst1.Items.Add(TButton(CtrlA).Caption);
    end;  
  end;  
end;

procedure TForm1.Btnx_3Click(Sender: TObject);
var
  I:Integer;
  CtrlA:TControl;
begin
  form2:=TForm2.Create(nil);

  lst1.Items.Clear;

  for I:=0 to form2.ControlCount-1 do
  begin
    CtrlA:=TControl(form2.Controls[I]);
    if CtrlA is TButton then
    begin
      lst1.Items.Add(TButton(CtrlA).Name);
      lst1.Items.Add(TButton(CtrlA).Caption);
    end;  
  end;    
end;

end.
